
import type { FilterRuleOptions, TypeConfig, RuleGenerationResult } from './types';
import { createBaseRule } from './ruleGeneratorUtils';

const uniqueConfig: TypeConfig = {
    class: null,  // 传奇物品可能是任何类型
    icon: 'Brown',
    iconShape: 'Star',
    name: '传奇',
    fontSize: 45
};

export function generateUniqueRule(options: FilterRuleOptions): RuleGenerationResult {
    let baseResult = createBaseRule(options, {
        name: uniqueConfig.name,
        class: uniqueConfig.class,
        defaultColor: '#AF6025',  // 传奇物品的特殊棕色
        defaultBgColor: '#000000',
        fontSize: uniqueConfig.fontSize,
        icon: uniqueConfig.icon,
        iconShape: uniqueConfig.iconShape
    });

    // 如果规则无效或被禁用，直接返回
    if (!baseResult.isValid || !baseResult.content) {
        return baseResult;
    }

    // 添加传奇物品特有的条件
    const lines = baseResult.content.split('\n');
    const insertIndex = lines.findIndex(line => line.includes('BaseType')) + 1;

    // 添加稀有度条件
    lines.splice(insertIndex, 0, '  Rarity Unique');

    // 添加特殊处理（比如六连接检查）
    if (options.value.includes('6L')) {
        lines.splice(insertIndex + 1, 0, '  LinkedSockets 6');
    }

    // 添加特殊音效和提示
    if (options.displayEnabled) {
        lines.push('  PlayAlertSoundPositional ShAlchemy 300');
        lines.push('  MinimapIcon 0 Brown Star');
        lines.push('  PlayEffect Brown');
    }

    baseResult.content = lines.join('\n');
    return baseResult;
}